﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Data;
using System.Collections.Generic;

public partial class UserControl_ucindex : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            //string IdItem = ((ImageButton)sender).CommandArgument;
            //ImageButton imagebutton = (ImageButton)sender;

            string IdItem = "1";

            BasePage.SetShoppingCartSesstion(IdItem + "|0");

            List<TblBookingDetail> arrItems = new List<TblBookingDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblBookingDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblBookingDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }

            flag = true;
            Session[Global.SESSION_TOTAL] = dTotalAmount;
            Session[Global.SESSION_CART] = arrItems;

        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (flag)
            Response.Redirect("~/MuaHang.aspx");
    }

    //public void UpdateShoppingCartSession()
    //{
    //    if (HttpContext.Current.Session[Global.SESSION_CART] != null)
    //    {
    //        List<TblBookingDetail> cartItems = (List<TblBookingDetail>)HttpContext.Current.Session[Global.SESSION_CART];

    //        int iQuantity = 0;
    //        double dAmount = 0;
    //        foreach (TblBookingDetail order in cartItems)
    //        {
    //            iQuantity += order.Quantity;
    //            //dAmount +=  order.TotalAmount;
    //            dAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
    //        }
    //        lbsoluong.Text = iQuantity.ToString();
    //        lblAmout.Text = dAmount.ToString("c");
    //    }
    //}
    protected void Button2_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            //string IdItem = ((ImageButton)sender).CommandArgument;
            //ImageButton imagebutton = (ImageButton)sender;

            string IdItem = "2";

            BasePage.SetShoppingCartSesstion(IdItem + "|0");

            List<TblBookingDetail> arrItems = new List<TblBookingDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblBookingDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblBookingDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }

            flag = true;
            Session[Global.SESSION_TOTAL] = dTotalAmount;
            Session[Global.SESSION_CART] = arrItems;

        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (flag)
            Response.Redirect("~/MuaHang.aspx");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            //string IdItem = ((ImageButton)sender).CommandArgument;
            //ImageButton imagebutton = (ImageButton)sender;

            string IdItem = "3";

            BasePage.SetShoppingCartSesstion(IdItem + "|0");

            List<TblBookingDetail> arrItems = new List<TblBookingDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblBookingDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblBookingDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }

            flag = true;
            Session[Global.SESSION_TOTAL] = dTotalAmount;
            Session[Global.SESSION_CART] = arrItems;

        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (flag)
            Response.Redirect("~/MuaHang.aspx");
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            //string IdItem = ((ImageButton)sender).CommandArgument;
            //ImageButton imagebutton = (ImageButton)sender;

            string IdItem = "4";

            BasePage.SetShoppingCartSesstion(IdItem + "|0");

            List<TblBookingDetail> arrItems = new List<TblBookingDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblBookingDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblBookingDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }

            flag = true;
            Session[Global.SESSION_TOTAL] = dTotalAmount;
            Session[Global.SESSION_CART] = arrItems;

        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (flag)
            Response.Redirect("~/MuaHang.aspx");
    }
}
